package cn.smxy.excel;

import cn.smxy.pojo.User;
import cn.smxy.util.DateFormatUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.hssf.record.HCenterRecord;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ContentRowHeight(65)
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER,
                verticalAlignment = VerticalAlignmentEnum.CENTER)
public class UserExcel implements Serializable {
    private static final long serialVersionUID = -7934825302014513167L;

    @ExcelProperty("用户编号")
    private String userId;

    @ExcelProperty("名称")
    private String userName;

    @ExcelProperty(value = "头像")
    @ColumnWidth(12)
    private URL userPhoto;

    @ExcelProperty("账号")
    private String userAccount;
    @ExcelProperty("密码")
    private String userPassword;

    @ExcelProperty("所在高校")
    private String collegeName;

    @ExcelProperty("邮箱")
    private String email;

    @ExcelProperty("手机号")
    private String userPhone;

    @ExcelProperty("用户角色")
    private String userRole;

    @ExcelProperty("创建时间")
    private String createTime;

    public UserExcel(User user,String collegeName) throws MalformedURLException {
        this.userId = user.getUserId().toString();
        this.userName = user.getUserName();
        this.userPhoto = new URL(user.getUserPhoto());
        this.userAccount = user.getUserAccount();
        this.userPassword = user.getUserPassword();
        this.collegeName = collegeName;
        this.email = user.getEmail();
        this.userPhone = user.getUserPhone();
        this.userRole = user.getUserRole() == 1 ? "普通用户":"学生";
        this.createTime = DateFormatUtil.dateFormat(user.getCreateTime());
    }
}
